package com.yantong.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @author: juzi
 * @date: 2021/12/6
 * @time: 11:26
 */
public class AliMsmUtils {

    public static void main(String[] args) {
        System.out.println(sendRegistCode("",""));
    }


    /**
     *  发送注册短信验证码
     * @param mobile
     * @param code 验证码
     * @return
     */
    public static boolean sendRegistCode(String mobile , String code){
        DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao", "LTAI4G6tqTk6mUzju4pMMCKR", "54TlSXaV3MGMKtHiH1FxrRQCgTLBC5");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("SignName", "琰记生活");
        request.putQueryParameter("TemplateCode", "SMS_229360183");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return response.getHttpStatus()==200;
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }

}
